package com.ujs.edu.medicine.dao;

import com.ujs.edu.medicine.dataobject.TableConsultDU;
import java.util.List;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
@Mapper
public interface TableConsultDUMapper {
    @Delete({
        "delete from table_consult_d_u",
        "where consultId = #{consultid,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer consultid);

    @Insert({
        "insert into table_consult_d_u (consultId, content, ",
        "fromuserId, doctorId, ",
        "files, receive, createtime, ",
        "postId)",
        "values (#{consultid,jdbcType=INTEGER}, #{content,jdbcType=VARCHAR}, ",
        "#{fromuserid,jdbcType=INTEGER}, #{doctorid,jdbcType=INTEGER}, ",
        "#{files,jdbcType=CHAR}, #{receive,jdbcType=INTEGER}, now(), ",
        "#{postid,jdbcType=INTEGER})"
    })
    int insert(TableConsultDU record);

    @Select({
        "select",
        "consultId, content, fromuserId, doctorId, files, receive, createtime, postId",
        "from table_consult_d_u",
        "where consultId = #{consultid,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="consultId", property="consultid", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="content", property="content", jdbcType=JdbcType.VARCHAR),
        @Result(column="fromuserId", property="fromuserid", jdbcType=JdbcType.INTEGER),
        @Result(column="doctorId", property="doctorid", jdbcType=JdbcType.INTEGER),
        @Result(column="files", property="files", jdbcType=JdbcType.CHAR),
        @Result(column="receive", property="receive", jdbcType=JdbcType.INTEGER),
        @Result(column="createtime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="postId", property="postid", jdbcType=JdbcType.INTEGER)
    })
    TableConsultDU selectByPrimaryKey(Integer consultid);

    @Select({
        "select",
        "consultId, content, fromuserId, doctorId, files, receive, createtime, postId",
        "from table_consult_d_u"
    })
    @Results({
        @Result(column="consultId", property="consultid", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="content", property="content", jdbcType=JdbcType.VARCHAR),
        @Result(column="fromuserId", property="fromuserid", jdbcType=JdbcType.INTEGER),
        @Result(column="doctorId", property="doctorid", jdbcType=JdbcType.INTEGER),
        @Result(column="files", property="files", jdbcType=JdbcType.CHAR),
        @Result(column="receive", property="receive", jdbcType=JdbcType.INTEGER),
        @Result(column="createtime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="postId", property="postid", jdbcType=JdbcType.INTEGER)
    })
    List<TableConsultDU> selectAll();

    /*通过医生id查询对应的用户会诊请求*/
    @Select("select * from table_consult_d_u where doctorId=#{doctorId}")
    List<TableConsultDU> selectBydoctorId(@Param("doctorId")Integer doctorId);

    @Update({
        "update table_consult_d_u",
        "set content = #{content,jdbcType=VARCHAR},",
          "fromuserId = #{fromuserid,jdbcType=INTEGER},",
          "doctorId = #{doctorid,jdbcType=INTEGER},",
          "files = #{files,jdbcType=CHAR},",
          "receive = #{receive,jdbcType=INTEGER},",
          "createtime = #{createtime,jdbcType=TIMESTAMP},",
          "postId = #{postid,jdbcType=INTEGER}",
        "where consultId = #{consultid,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(TableConsultDU record);
}